import collections
class Solution(object):
    def processQueries(self, queries, m):
        nums = collections.deque([i + 1 for i in range(m)])
        n = len(queries)
        ans = [0] * n
        for i in range(n):
            index = nums.index(queries[i])
            ans[i] = index
            nums.appendleft(queries[i])
            del nums[index + 1]
        return ans

data = Solution()
queries = [3,1,2,1]
m = 5
print(data.processQueries(queries, m))